#pragma once

#include "effectbase.h"
#include <osg/NodeCallback>
#include <osg\Timer>

namespace CoreBase
{
	class Viewer;
}

namespace VrDataCore
{
	class VRDATACORE_EXPORT MotionEffect:public EffectBase
	{
	public:
		MotionEffect();
	protected:
		~MotionEffect(){}
		bool													_update;
		bool													_mustUpdate;
	public:
		virtual void update(){}
		virtual void onMapLoadBegin(CoreBase::Map*){}
		virtual void onMapLoadEnd(CoreBase::Map*){}
		virtual void reset(){}
		virtual void apply(CoreBase::ActorBase* actor){}
		virtual void unApply(CoreBase::ActorBase* actor){}
	};

	class UniformMotionUpdateCallback : public osg::NodeCallback
	{
	public:
		UniformMotionUpdateCallback(MotionEffect* un);
		~UniformMotionUpdateCallback(){} ;
		virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
	protected:
		MotionEffect*				_un ;
	};

	class VRDATACORE_EXPORT UniformMotion:public MotionEffect
	{
	public:
		UniformMotion();
	protected:
		~UniformMotion();
	public:
		void setEndPosition(osg::Vec3 pos);
		osg::Vec3 getEndPostion();
		void setStartPosition(osg::Vec3 pos);
		osg::Vec3 getStartPostion();
		void setEndRotation(osg::Vec3 rota);
		osg::Vec3 getEndRotation();
		void setStartRotation(osg::Vec3 rota);
		osg::Vec3 getStartRotation();
		void setMotionTotalTime(float time);
		float setMotionTotalTime();
		virtual void update();
		virtual void apply(CoreBase::ActorBase* actor);
		virtual void unApply(CoreBase::ActorBase* actor);
	private:
		osg::Vec3											_endPos;
		osg::Vec3											_startPos;
		osg::Vec3											_startRotation;
		osg::Vec3											_endRotation;
		float												_totalTime;
		osg::Timer_t										_startTick;
		osg::ref_ptr<UniformMotionUpdateCallback>			_updateCallback;
		bool												_setupCallback;
		int													_rotateFrame;
	};

	class VRDATACORE_EXPORT MotionTrackEffect:public MotionEffect
	{
	public:
		MotionTrackEffect();
	protected:
		~MotionTrackEffect();
		void startEffect(CoreBase::ActorBase* actor);
	public:
		void setLoop(QString loop);
		QString getLoop();
		void setTrackPoint(QList<osg::Vec3> pointvector);
		QList<osg::Vec3> getTrackPoint();
		void setTrackRotationList(QList<double> list);
		QList<double> getTrackRotationList();
		void setSpeed(float s);
		float getSpeed();
		virtual void update();
		virtual void apply(CoreBase::ActorBase* actor);
		virtual void unApply(CoreBase::ActorBase* actor);
		void reStart();
		virtual void buildPropertyMap();
	private:
		osg::Timer_t								_startTick;
		bool										_update;
		osg::ref_ptr<UniformMotionUpdateCallback>	_updateCallback;
		bool										_setupCallback;
		QList<osg::Vec3f>							_pointList;
		QList<double>								_trackRotationList;
		QList<double>								_intervalList;
		bool										_isLoop;
		bool										_waitingRestart;
		float										_speed;
		int											_currentIndex;
		osg::Vec3									_startRotation;
		osg::Vec3									_endRotation;
		int											_rotateFrame;
	};

	class VRDATACORE_EXPORT StaticOnOceanEffect:public MotionEffect
	{
	public:
		StaticOnOceanEffect();
	protected:
		~StaticOnOceanEffect();
	public:
		virtual void update();
		virtual void apply(CoreBase::ActorBase* actor);
		virtual void unApply(CoreBase::ActorBase* actor);
		virtual void buildPropertyMap();
	private:
		bool										_update;
		osg::ref_ptr<UniformMotionUpdateCallback>	_updateCallback;
		bool										_setupCallback;
	};
}